//added comment to test version control

siteViewModel = kendo.observable({
	dirty: false,
	// model properties
	site_id: 0,
	organization_id: 0,
	site: "",
	address: "",
	city: "",
	zip_code: "",
	county_id: 0,
	site_type: "",
	computers: "",
	date_created: "",
	// model datasource
	//datasource: sites,
	// fk datasources
	counties: counties,
	// lookup datasources
	siteTypes: siteTypes,
	siteComputers: siteComputers,
	// functions and caluculated properties
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("site_id"),
					objType: "site",
					modalTemplate: "formModalTemplate", 
					modalId: "site" + this.get("site_id") + "FormModal",
					modalTitle: "Site",
					contentType: "form", 
					contentTemplate: "siteFormTemplate", 
					contentId: "site" + this.get("site_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("site_id"),
					objType: "site",
					modalTemplate: "detailModalTemplate", 
					modalId: "site" + this.get("site_id") + "DetailModal",
					modalTitle: "Site",
					contentType: "detail", 
					contentTemplate: "siteDetailTemplate", 
					contentId: "site" + this.get("site_id") + "Detail"
				},
				inline: {
					id: this.get("site_id"),
					objType: "site",
					inlineId: "siteDetailInline",
					contentType: "detail", 
					contentTemplate: "siteDetailTemplate", 
					contentId: "site" + this.get("site_id") + "Detail"
				}
			},
			list: {
				modal: {
					objType: "site",
					modalTemplate: "listModalTemplate", 
					modalId: "sitesListModal",
					modalTitle: "Sites",
					contentType: "list", 
					contentTemplate: "sitesListTemplate", 
					contentId: "sitesList"
				},
				inline: {
					objType: "site",
					inlineId: "sitesListInline",
					contentType: "list", 
					contentTemplate: "sitesListTemplate", 
					contentId: "sitesList"
				}
			}
		}
	},
	change: function() {
		this.set("dirty", true);
		return;
	}
});
userViewModel = kendo.observable({
	dirty: false,
	// model properties
	user_id: 0,
	approved: false,
	deleted: false,
	archived: false,
	organization_id: 0,
	organization2_id: 0,
	organization3_id: 0,
	role: "",
	region_ids: "",
	first_name: "",
	last_name: "",
	title: "",
	email: "",
	password: "",
	phone: "",
	extension: "",
	login_token: "",
	date_created: "",
	// model datasource
	//datasource: users,
	// lookup datasources
	statuses: statuses,
	roles: roles,
	// functions and caluculated properties
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("user_id"),
					objType: "user",
					modalTemplate: "formModalTemplate", 
					modalId: "user" + this.get("user_id") + "FormModal",
					modalTitle: "User",
					contentType: "form", 
					contentTemplate: "userFormTemplate", 
					contentId: "user" + this.get("user_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("user_id"),
					objType: "user",
					modalTemplate: "detailModalTemplate", 
					modalId: "user" + this.get("user_id") + "DetailModal",
					modalTitle: "User",
					contentType: "detail", 
					contentTemplate: "userDetailTemplate", 
					contentId: "user" + this.get("user_id") + "Detail"},
				inline: {}
			}
		}
	},
	status: function() {
		return this.get("approved") ? "Approved" : "Not approved";
	},
	fullName: function() {
		return this.get("first_name") + " " + this.get("last_name")
	},
	isSelf: function() {
		return this.get("user_id") == authUser.userId ? true : false;
	},
	isNotSelf:  function() {
		return this.get("user_id") != authUser.userId ? true : false;
	},
	change: function() {
		this.set("dirty", true);
		return;
	}
});
workshopViewModel = kendo.observable({
	dirty: false,
	// model properties
	workshop_id: 0,
	approved: false,
	deleted: false,
	program_year: "",
	organization_id: 0,
	site_id: 0,
	organizer_id: 0,
	manager_id: 0,
	workshop_date: "",
	start_time: "",
	end_time: "",
	evaluation_code: "",
	pb_survey_count: 0,
	pb_survey_count_status: "Uninitiated",
	pb_shipped_date: "",
	pb_notes: "",
	anticipated_students: 0,
	anticipated_volunteers: 0,
	anticipated_computers: 0,
	financial_aid_presentation: false,
	fafsa_on_the_web: false,
	online: true,
	offline_reasons: "",
	offline_reason_other: "",
	small_group: false,
	tax_assistance: false,
	separate_areas: false,
	ab540: false,
	foster_youth: false,
	alt_language_workshop: false,
	alt_languages: "",
	translators: false,
	translator_languages: "",
	refreshments: false,
	child_care: false,
	other_services: false,
	other_services_description: "",
	date_created: "",
	// model datasource
	//datasource: workshops,
	// fk datasources
	organizations: organizations,
	sites: sites,
	//sites: sites,
	managers: managers,
	organizers: organizers,
	// lookup datasources
	statuses: statuses,
	workshopHolidays: workshopHolidays,
	offlineReasons: offlineReasons,
	/*site: function() {
		if (this.get("site_id") > 0) {
			return this.get("sites").get(this.get("site_id")).site;
		} else {
			return null;
		}
	},*/
	// functions and caluculated properties
	filterSites: function() {
		//console.log("filterSites triggered");
		/*var siteId = this.get("site_id");
		var self = this;
		sites.bind("change", function() {
			//console.log("sites change event triggered");
			if (self.get("dirty")) {
				self.set("site_id", 0);
			} else { 
				self.set("site_id", siteId);
			}
			sites.unbind("change");
		});*/
		sites.read({organization_id: this.get("organization_id")});
	},
	offlineReasonOtherChecked: function() {
		return $.inArray("Other", this.get("offline_reasons")) != -1 ? true : false;
	},
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("workshop_id"),
					objType: "workshop",
					modalTemplate: "formModalTemplate", 
					modalId: "workshop" + this.get("workshop_id") + "FormModal",
					modalTitle: "Workshop",
					contentType: "form", 
					contentTemplate: "workshopFormTemplate", 
					contentId: "workshop" + this.get("workshop_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("workshop_id"),
					objType: "workshop",
					modalTemplate: "detailModalTemplate", 
					modalId: "workshop" + this.get("workshop_id") + "DetailModal",
					modalTitle: "Workshop",
					contentType: "detail", 
					contentTemplate: "workshopDetailTemplate", 
					contentId: "workshop" + this.get("workshop_id") + "Detail"},
				inline: {}
			},
			list: {
				inline: {
					//id: this.get("workshop_id"),
					objType: "workshop",
					datasource: workshops,
					inlineTemplate: "listInlineTemplate", 
					inlineId: "workshopsListInline",
					inlineTitle: "Workshops",
					contentType: "list", 
					contentTemplate: "workshopsListTemplate", 
					contentId: "workshopsList"},
				modal: {}
			}
		}
	},
	monitorOnline: function() {
		setTimeout(function() {
			if (!workshopViewModel.get("online")) {
				if (modalArray.length > 0 && modalArray[modalArray.length - 1].modalTemplate == "formModalTemplate") {
					toggleModalButtons(modalArray[modalArray.length - 1].modalId, true);
				};
				$("#offlineReasonsPopover").popover("show");
				kendo.bind($("#offlineReasonsForm"), workshopViewModel);
			} else {
				$("#offlineReasonsPopover").popover("hide");
				workshopViewModel.set("offline_reasons", []);
				if (modalArray.length > 0 && modalArray[modalArray.length - 1].modalTemplate == "formModalTemplate") {
					toggleModalButtons(modalArray[modalArray.length - 1].modalId, false);
				};		
			}
		}, 400)
	},
	closeOfflineReasons: function(e) {
		e.preventDefault();
		if (this.validateOfflineReasons()) {
			$("#offlineReasonsAlert").hide();
			$("#offlineReasonsPopover").popover("hide");
			if (modalArray.length > 0 && modalArray[modalArray.length - 1].modalTemplate == "formModalTemplate") {
				toggleModalButtons(modalArray[modalArray.length - 1].modalId, false);
			};
		} else {
			$("#offlineReasonsAlert").show();
			return false;
		}
	},
	validateOfflineReasons: function() {
		if (!this.get("online") && this.get("offline_reasons").length == 0) {
			return false;
		} else if (this.get("offline_reasons").length > 0) {
			if ($.inArray("Other", this.get("offline_reasons")) > -1 && this.get("offline_reason_other").length == 0) {
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	},
	status: function() {
		return this.get("approved") ? "Approved" : "Not approved";
	},
	validateWorkshopDate: function(e) {
		//this.hideWorkshopDatePopover();
		$.each(this.get("workshopHolidays"), function(index, value) {
			if (kendo.toString(value.holiday, "d") == kendo.toString(e.data.workshop_date, "d")) {
				if (value.forbid) {
					workshopViewModel.set("workshop_date", "");
					$("#workshopDatePopover").popover({
						trigger: "manual",
						placement: "right",
						html: true,
						content: "<div class='popoverBlock'>The date you selected is <strong>" + value.name + "</strong> and is not an approved workshop date.</div><div class='popoverBlock'>Please select another date for this workshop.</div><div class='popoverBlock'><button class='btn btn-mini btn-success' onclick='$(\"\#workshopDatePopover\").popover(\"destroy\");'>Close</button></div>",
						title: "Invalid Workshop Date"
					}).popover("show");
					//alert("The date you selected is " + value.name + " and is not an approved workshop date.\n\nPlease select another date for this workshop.");
				} else {
					workshopViewModel.set("workshop_date", kendo.toString(e.data.workshop_date, "d"));
					$("#workshopDatePopover").popover({
						trigger: "manual",
						placement: "right",
						html: true,
						content: "<div class='popoverBlock'>The date you selected is <strong>" + value.name + "</strong>.</div><div class='popoverBlock'>Please consider another date for this workshop.</div><div class='popoverBlock'><button class='btn btn-mini btn-success' onclick='$(\"\#workshopDatePopover\").popover(\"destroy\");'>Close</button></div>",
						title: "Discouraged Workshop Date"
					}).popover("show");
				}
			}
		})
	},
	validateStartTime: function(e) {
		if (jQuery.type(kendo.parseDate(this.get("workshop_date"))) === "date") {
			var workshopDate = kendo.parseDate(this.get("workshop_date"));
			var dayOfWeek = workshopDate.getDay();
			if (dayOfWeek > 0 && dayOfWeek < 6) {
				if (jQuery.type(kendo.parseDate(this.get("start_time"))) == "date") {
					var startTimeDate = kendo.parseDate(this.get("start_time"));
					var startTime = new Date(0,0,0,startTimeDate.getHours(),startTimeDate.getMinutes(),0);
					var noon = new Date(0,0,0,12,0,0);
					if (startTime < noon) {
						this.set("start_time", "");
						$("#invalidStartTimePopover").popover({
							trigger: "manual",
							placement: "right",
							html: true,
							content: "<div class='popoverBlock'>The start time you selected is before noon on a weekday.  Holding a workshop before noon on a weekday must pre-approved by Cash for College.</div><div class='popoverBlock'>Please enter a start time on or before noon or contact Cash for College at cashforcollege@csac.ca.gov to approved your workshop.</div><div class='popoverBlock'><button class='btn btn-mini btn-success' onclick='$(\"\#invalidStartTimePopover\").popover(\"destroy\");'>Close</button></div>",
							title: "Invalid Start Time"
						}).popover("show");
					}
				}
			}
		}
	},
	validateEndTime: function(e) {
		
	},
	hideWorkshopDatePopover: function() {
		$("#workshopDatePopover").popover("destroy");
	},
	createSite: function() {
		get("site", 0, 'edit', 'modal');
	},
	editSite: function() {
		var siteId = typeof this.get("site_id") == "number" ? this.get("site_id") : 0;
		get("site", siteId, 'edit', 'modal');
	},
	createManager: function() {
		get("user", 0, 'edit', 'modal');
	},
	editManager: function() {
		var managerId = typeof this.get("manager_id") == "number" ? this.get("manager_id") : 0;
		get("user", managerId, 'edit', 'modal');
	},
	createOrganizer: function() {
		get("user", 0, 'edit', 'modal');
	},
	editOrganizer: function() {
		var organizerId = typeof this.get("organizer_id") == "number" ? this.get("organizer_id") : 0;
		get("user", organizerId, 'edit', 'modal');
	},
	change: function() {
		this.set("dirty", true);
		return;
	}
});
oapViewModel = kendo.observable({
	dirty: false,
	// properties
	oap_id: 0,
	organization_id: 0,
	created_by_id: 0,
	deleted: false,
	program_year: "",
	workshop_count: 0,
	student_target: 0,
	oap_value_ids: "",
	campus_other: "",
	parent_other: "",
	community_partner_other: "",
	date_created: "",
	// lookup databases
	oapValues: oapValues,
	// functions and calculated properties
	currentStep: 1,
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("oap_id"),
					objType: "oap",
					modalTemplate: "wizardModalTemplate", 
					modalId: "oap" + this.get("oap_id") + "WizardModal",
					modalTitle: "Outreach Action Plan",
					contentType: "wizard", 
					contentTemplate: "oapWizardTemplate", 
					contentId: "oap" + this.get("oap_id") + "Form"
				}
			},
			detail: {
				modal: {
					id: this.get("oap_id"),
					objType: "oap",
					modalTemplate: "detailModalTemplate", 
					modalId: "oap" + this.get("oap_id") + "DetailModal",
					modalTitle: "Outreach Action Plan",
					contentType: "detail", 
					contentTemplate: "oapDetailTemplate", 
					contentId: "oap" + this.get("oap_id") + "Detail"
				},
				inline: {
					id: this.get("oap_id"),
					objType: "oap",
					inlineId: "oapDetailInline",
					contentType: "detail", 
					contentTemplate: "oapDetailTemplate", 
					contentId: "oap" + this.get("oap") + "Detail"
				}
			}
		}
	},
	validateStep: function() {
		var ret = true;
		//console.log("validateStep: oap step " + this.get("currentStep"));
		switch (this.get("currentStep")) {
			case 1:
				var incompleteFields = [];
				if (typeof parseInt(this.get("workshop_count"), 10) != "number" || parseInt(this.get("workshop_count"), 10) == 0) {
					incompleteFields.push("Number of workshops");
				}
				if (typeof parseInt(this.get("student_target"), 10) != "number" || parseInt(this.get("student_target"), 10) == 0) {
					incompleteFields.push("Total number of students");
				}
				if (incompleteFields.length > 0) {
					ret = andList(incompleteFields) + " are required";
				}		
			break;
			case 2:
				if (this.get("oap_value_ids").length < 2) {
					ret = "Please select at least 2 items from this list";
				}
			break;
			case 3:
				if (this.get("oap_value_ids").length < 4) {
					ret = "Please select at least 2 items from this list";
				}
			break;
			case 4:
				if (this.get("oap_value_ids").length < 6) {
					ret = "Please select at least 2 items from this list";
				} 
				/*else {
					save("oap", this.get("oap_id"));
				}*/
			break;
			case 5:
			break;		
		}
		return ret;
	},
	step: function() {
		switch (this.get("currentStep")) {
			case 1:

			break;
			case 2:
			
			break;
			case 3:
			
			break;
			case 4:
				
			break;
			case 5:

			break;	
		}
		return;
	},
	averageWarningVisible: true,
	averageStudentsPerWorkshop: function() {
		if (typeof(parseInt(this.get("workshop_count"))) == "number" && this.get("workshop_count") > 0 && typeof(parseInt(this.get("student_count"))) == "number" && this.get("student_target") > 0) {
			var ave = parseInt(this.get("student_target")) / parseInt(this.get("workshop_count"))
			if (ave < 25) {
				this.set("averageWarningVisible", true);
			} else {
				this.set("averageWarningVisible", false);
			}
			return ave;
		} else {
			this.set("averageWarningVisible", false);
			return 0;
		}
	},
	updateOnKeyup: function(e) {
		this.set(e.currentTarget.name, $(e.currentTarget).val());
	},
	change: function() {
		this.set("dirty", true);
		//console.log(this);
		return;
	}
});
organizationViewModel = kendo.observable({
	dirty: false,
	// model properties
	organization_id: 0,
	approved: false,
	deleted: false,
	archived: false,
	organization: "",
	address: "",
	city: "",
	zip_code: "",
	county_id: 0,
	county: "",
	region_id: 0,
	region: "",
	date_created: "",
	// model datasource
	//datasource: organizations,
	// fk datasources
	counties: counties,
	// lookup datasources
	statuses: statuses,
	// functions and caluculated properties
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("organization_id"),
					objType: "organization",
					modalTemplate: "formModalTemplate", 
					modalId: "organization" + this.get("organization_id") + "FormModal",
					modalTitle: "Organization",
					contentType: "form", 
					contentTemplate: "organizationFormTemplate", 
					contentId: "organization" + this.get("organization_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("organization_id"),
					objType: "organization",
					modalTemplate: "detailModalTemplate", 
					modalId: "organization" + this.get("organization_id") + "DetailModal",
					modalTitle: "Organization",
					contentType: "detail", 
					contentTemplate: "organizationDetailTemplate", 
					contentId: "organization" + this.get("organization_id") + "Detail"
				},
				inline: {
					id: this.get("organization_id"),
					objType: "organization",
					inlineId: "organizationDetailInline",
					contentType: "detail", 
					contentTemplate: "organizationDetailTemplate", 
					contentId: "organization" + this.get("organization_id") + "Detail"
				}
			}
		}
	},
	status: function() {
		return this.get("approved") ? "Approved" : "Not approved";
	},
	change: function() {
		this.set("dirty", true);
		return;
	}
});
paViewModel = kendo.observable({
	dirty: false,
	// model properties
	pa_id: 0,
	organization_id: 0,
	accepted_by_id: 0,
	deleted: false,
	program_year: "",
	pa: "",
	date_created: "",
	// model datasource
	//datasource: pas,
	// functions and calculated properties
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("pa_id"),
					objType: "pa",
					modalTemplate: "acceptModalTemplate", 
					modalId: "pa" + this.get("pa_id") + "AcceptModal",
					modalTitle: "Partnership Agreement",
					contentType: "form", 
					contentTemplate: "paFormTemplate", 
					contentId: "pa" + this.get("pa_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("pa_id"),
					objType: "pa",
					modalTemplate: "detailModalTemplate", 
					modalId: "pa" + this.get("pa_id") + "DetailModal",
					modalTitle: "Partnership Agreement",
					contentType: "detail", 
					contentTemplate: "paDetailTemplate", 
					contentId: "pa" + this.get("pa_id") + "Detail"},
				inline: {}
			}
		}
	},
	showPA1: function() {
		return $.inArray(authUser.regionId, [1,2,3,5,12]) != -1 ? true : false;
	},
	showPA2: function() {
		return $.inArray(authUser.regionId, [4,6,7,8,9,10,11,13,14]) != -1 ? true : false;
	},
	change: function() {
		this.set("dirty", true);
		return;
	}
});
workshopVolunteerViewModel = kendo.observable({
	dirty: false,
	// properties
	workshop_volunteer_id: 0,
	deleted: false,
	workshop_id: 0,
	volunteer_id: 0,
	confirmed: false,
	acknowledged: false,
	date_created: "",
	organization_id: 0,
	workshop_date: "",
	start_time: "",
	end_time: "",
	site: "",
	site_type: "",
	first_name: "",
	last_name: "",
	title: "",
	organization: "",
	address: "",
	city: "",
	zip_code: "",
	phone: "",
	email: "",
	travel_distance: 0,
	financial_aid_expert: false,
	fafsa_expert: false,
	finance_expert: false,
	tax_expert: false,
	outreach_expert: false,
	ab540_expert: false,
	technology_expert: false,
	translator: false,
	translator_languages: "",
	student: false,
	shirt_size: "",
	// lookup datasources
	workshops: workshops,
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("workshop_volunteer_id"),
					objType: "workshopVolunteer",
					modalTemplate: "formModalTemplate", 
					modalId: "workshopVolunteer" + this.get("workshop_volunteer_id") + "FormModal",
					modalTitle: "Workshop Volunteer",
					contentType: "form", 
					contentTemplate: "workshopVolunteerFormTemplate", 
					contentId: "workshopVolunteer" + this.get("workshop_volunteer_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("workshop_volunteer_id"),
					objType: "workshopVolunteer",
					modalTemplate: "detailModalTemplate", 
					modalId: "workshopVolunteer" + this.get("workshop_volunteer_id") + "DetailModal",
					modalTitle: "Workshop Volunteer",
					contentType: "detail", 
					contentTemplate: "workshopVolunteerDetailTemplate", 
					contentId: "workshopVolunteer" + this.get("workshop_volunteer_id") + "Detail"},
				inline: {}
			}
		}
	},
	change: function() {
		this.set("dirty", true);
		console.log(this);
		//console.log("workshopVolunteerViewModel changed");
		return;
	}
});
orderViewModel = kendo.observable({
	dirty: false,
	// model properties
	order_id: 0,
	approved: false,
	deleted: false,
	program_year: "",
	organization_id: 0,
	ordered_by_id: 0,
	anticipated_ship_date: "",
	fulfillment_date: "",
	student_count: 0,
	volunteer_count: 0,
	order_value_ids: "",
	quantities: "",
	shipping_organization: "",
	shipping_department: "",
	shipping_name: "",
	shipping_address: "",
	shipping_city: "",
	shipping_zip_code: "",
	shipping_phone: "",
	shipping_intstructions: "",
	date_created: "",
	// lookup datasources
	orderValues: orderValues,
	statuses: statuses,
	// functions and caluculated properties
	currentStep: 1,
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("order_id"),
					objType: "order",
					modalTemplate: "wizardModalTemplate", 
					modalId: "order" + this.get("order_id") + "WizardModal",
					modalTitle: "Order",
					/*modalOnload: function() {
						var stepNext = function() {
							uiConfig.currentStep = uiConfig.currentStep - 1;
							var nextStep = uiConfig.currentStep + 1;
							var backStep = uiConfig.currentStep - 1;
							if (!$("#" + uiConfig.contentId + " .step" + nextStep).length) {
								$("#" + uiConfig.modalId + " .nextButton").hide();
								$("#" + uiConfig.modalId + " .finishButton").show();
							}
							$("#" + uiConfig.modalId + " .backButton").show();
							$("#" + uiConfig.contentId + " .step" + backStep).hide();
							$("#" + uiConfig.contentId + " .step" + uiConfig.currentStep).show();
						};
						var stepBack = function() {
							uiConfig.currentStep = uiConfig.currentStep - 1;
							var nextStep = uiConfig.currentStep + 1;
							var backStep = uiConfig.currentStep - 1;
							if (!$("#" + uiConfig.contentId + " .step" + backStep).length) {
								$("#" + uiConfig.modalId + " .backButton").hide();
							}
							$("#" + uiConfig.modalId + " .finishButton").hide();
							$("#" + uiConfig.modalId + " .nextButton").show();
							$("#" + uiConfig.contentId + " .step" + nextStep).hide();
							$("#" + uiConfig.contentId + " .step" + uiConfig.currentStep).show();
						};
						var finish = function() {
							save(uiConfig.objType, uiConfig.id);
						};
						$("#" + uiConfig.modalId + " .nextButton").unbind("click").bind("click", stepNext);
						$("#" + uiConfig.modalId + " .backButton").unbind("click").bind("click", stepBack);
						$("#" + uiConfig.modalId + " .finishButton").unbind("click").bind("click", finish);
						$("#" + uiConfig.modalId + " .cancelButton").unbind("click").bind("click", closeModal);
						$("#" + uiConfig.modalId + " .backButton").hide();
						$("#" + uiConfig.modalId + " .finishButton").hide();
						$("#" + uiConfig.modalId + " .nextButton").show();
						$("#" + uiConfig.contentId + " .step" + uiConfig.currentStep).show();
					},*/
					contentType: "wizard", 
					contentTemplate: "orderWizardTemplate", 
					contentId: "order" + this.get("order_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("order_id"),
					objType: "order",
					modalTemplate: "detailModalTemplate", 
					modalId: "order" + this.get("order_id") + "DetailModal",
					modalTitle: "Order",
					contentType: "detail", 
					contentTemplate: "orderDetailTemplate", 
					contentId: "order" + this.get("order_id") + "Detail"
				},
				inline: {}
			}
		}
	},
	validateStep: function() {
		var ret = true;
		//console.log("validateStep: oap step " + this.get("currentStep"));
		switch (this.get("currentStep")) {
			case 1:
				var incompleteFields = [];
				if (this.get("shipping_name").length == 0) {
					incompleteFields.push("Recipient Name");
				}
				if (this.get("shipping_address").length == 0) {
					incompleteFields.push("Address");
				}
				if (this.get("shipping_city").length == 0) {
					incompleteFields.push("City");
				}
				if (this.get("shipping_zip_code").length == 0) {
					incompleteFields.push("Zip Code");
				}
				if (this.get("shipping_phone").length == 0) {
					incompleteFields.push("Phone");
				}
				if (incompleteFields.length > 0) {
					ret = andList(incompleteFields) + " are required";
				}
				/*var validator = $("#accountWizard").kendoValidator({messages: validatorMessages}).data("kendoValidator");
				if (validator.validate() == false) {
					ret = "Please complete the missing fields";
				};
				/*if (this.get("email").length == 0) {
					ret = "E-mail is required";
				} else {
					var dupeEmails = getDuplicateEmails(this.get("email"));
					if (dupeEmails.length == 0) {
						this.set("user_id", 0);
					} else if (dupeEmails.length == 1) {
						this.set("user_id", dupeEmails[0].user_id);
						ret = this.get("email") + " is already associated with an account <a href='\#' class='btn btn-success' onClick='sendPassword()'>Send password</a>";	
					} else {
						ret = "The system can not verify your email";
					}
				}*/			
			break;
			case 2:
				/*var incompleteFields = [];
				if (this.get("first_name").length == 0) {
					incompleteFields.push("First Name");
				}
				if (this.get("last_name").length == 0) {
					incompleteFields.push("Last Name");
				}
				if (this.get("password").length == 0) {
					incompleteFields.push("Password");
				}
				if (this.get("phone").length == 0) {
					incompleteFields.push("Phone");
				}
				if (incompleteFields.length > 0) {
					ret = andList(incompleteFields) + " are required";
				}
				/*var validator = $("#accountWizard").kendoValidator({messages: validatorMessages}).data("kendoValidator");
				if (validator.validate() == false) {
					ret = "Please complete the missing fields";
				};*/
			break;
			case 3:
				/*if (!typeof parseInt(this.get("organization_id"), 10) == "number") {
					ret = "A selection is required";
				} else if (parseInt(this.get("organization_id"), 10) > 0) {
					this.set("currentStep", 4);	
				}*/
				save("order", this.get("order_id"));
			break;
			case 4:
				/*var incompleteFields = [];
				if (this.get("organization").length == 0) {
					incompleteFields.push("Organization");
				}
				if (this.get("address").length == 0) {
					incompleteFields.push("Address");
				}
				if (this.get("city").length == 0) {
					incompleteFields.push("City");
				}
				if (this.get("zip_code").length == 0) {
					incompleteFields.push("Zip Code");
				}
				if (this.get("county_id") == 0) {
					incompleteFields.push("County");
				}
				if (incompleteFields.length > 0) {
					ret = andList(incompleteFields) + " are required";
				}*/
			break;
			case 5:
			
			break;		
		}
		return ret;
	},
	step: function() {
		switch (this.get("currentStep")) {
			case 1:
				/*this.set("user_id", 0);
				this.set("organization_id", 0);
				this.set("prevEmail", "");*/
			break;
			case 2:
			
			break;
			case 3:
			
			break;
			case 4:
			
			break;
			case 5:
			
			break;	
		}
		return;
	},
	status: function() {
		return this.get("approved") ? "Approved" : "Not approved";
	},
	change: function() {
		this.set("dirty", true);
		return;
	}
});
volunteerViewModel = kendo.observable({
	dirty: false,
	// properties
	volunteer_id: 0,
	deleted: false,
	organization_id: 0,
	first_name: "",
	last_name: "",
	title: "",
	organization: "",
	address: "",
	city: "",
	zip_code: "",
	phone: "",
	email: "",
	travel_distance: 0,
	financial_aid_expert: false,
	fafsa_expert: false,
	finance_expert: false,
	tax_expert: false,
	outreach_expert: false,
	ab540_expert: false,
	technology_expert: false,
	translator: false,
	translator_languages: "",
	student: false,
	shirt_size: "",	
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: this.get("volunteer_id"),
					objType: "volunteer",
					modalTemplate: "formModalTemplate", 
					modalId: "volunteer" + this.get("volunteer_id") + "FormModal",
					modalTitle: "Volunteer",
					contentType: "form", 
					contentTemplate: "volunteerFormTemplate", 
					contentId: "volunteer" + this.get("volunteer_id") + "Form"
				},
				inline: {}
			},
			detail: {
				modal: {
					id: this.get("volunteer_id"),
					objType: "volunteer",
					modalTemplate: "detailModalTemplate", 
					modalId: "volunteer" + this.get("volunteer_id") + "DetailModal",
					modalTitle: "Volunteer",
					contentType: "detail", 
					contentTemplate: "volunteerDetailTemplate", 
					contentId: "volunteer" + this.get("volunteer_id") + "Detail"},
				inline: {}
			}
		}
	},
	fullName: function() {
		return this.get("first_name") + " " + this.get("last_name")
	},
	change: function() {
		this.set("dirty", true);
		return;
	}
});
accountViewModel = kendo.observable({
	dirty: false,
	// model properties
	// user properies
	user_id: 0,
	organization_id: 0,
	organization2_id: 0,
	organization3_id: 0,
	role: "",
	region_ids: "",
	first_name: "",
	last_name: "",
	title: "",
	email: "",
	password: "",
	phone: "",
	// organization properites
	organization: "",
	address: "",
	city: "",
	zip_code: "",
	county_id: 0,
	// common properties
	approved: false,
	deleted: false,
	date_created: "",
	// lookup datasources
	organizations: organizations,
	counties: counties,
	// functions and calculated properties
	prevEmail: "",
	isNewUser: function() {
		return this.get("user_id") == 0 ? true : false;
	},
	isNewOrganization: function() {
		return this.get("organization_id") == 0 ? true : false;
	},
	setOrganizationId: function(organizationId) {
		this.set("organization_id", organizationId);
		return;
	},
	currentStep: 1,
	uiConfig: function() {
		return {
			edit: {
				modal: {
					id: 0,
					objType: "account",
					modalTemplate: "wizardModalTemplate",
					modalId: "accountWizardModal",
					modalTitle: "Create Account",
					contentType: "wizard", 
					contentTemplate: "accountWizardTemplate", 
					contentId: "accountWizard"
				}
			},
			detail: {
				modal: {
					id: 0,
					objType: "account",
					modalTemplate: "detailModalTemplate", 
					modalId: "accountDetailModal",
					modalTitle: "Account",
					contentType: "detail", 
					contentTemplate: "accountDetailTemplate", 
					contentId: "accountDetail"
				}
			}
		}
	},
	validateStep: function() {
		var ret = true;
		switch (this.get("currentStep")) {
			case 1:
				if (this.get("email").length == 0) {
					ret = "E-mail is required";
				} else {
					var dupeEmails = getDuplicateEmails(this.get("email"));
					if (dupeEmails.length == 0) {
						this.set("user_id", 0);
					} else if (dupeEmails.length == 1) {
						this.set("user_id", dupeEmails[0].user_id);
						ret = this.get("email") + " is already associated with an account <a href='\#' class='btn btn-success' onClick='sendPassword()'>Send password</a>";	
					} else {
						ret = "The system can not verify your email";
					}
				}				
			break;
			case 2:
				var incompleteFields = [];
				if (this.get("first_name").length == 0) {
					incompleteFields.push("First Name");
				}
				if (this.get("last_name").length == 0) {
					incompleteFields.push("Last Name");
				}
				if (this.get("password").length == 0) {
					incompleteFields.push("Password");
				}
				if (this.get("phone").length == 0) {
					incompleteFields.push("Phone");
				}
				if (incompleteFields.length > 0) {
					ret = andList(incompleteFields) + " are required";
				}
				/*var validator = $("#accountWizard").kendoValidator({messages: validatorMessages}).data("kendoValidator");
				if (validator.validate() == false) {
					ret = "Please complete the missing fields";
				};*/
			break;
			case 3:
				if (!typeof parseInt(this.get("organization_id"), 10) == "number") {
					ret = "A selection is required";
				} else if (parseInt(this.get("organization_id"), 10) > 0) {
					this.set("currentStep", 4);	
				}
			break;
			case 4:
				var incompleteFields = [];
				if (this.get("organization").length == 0) {
					incompleteFields.push("Organization");
				}
				if (this.get("address").length == 0) {
					incompleteFields.push("Address");
				}
				if (this.get("city").length == 0) {
					incompleteFields.push("City");
				}
				if (this.get("zip_code").length == 0) {
					incompleteFields.push("Zip Code");
				}
				if (this.get("county_id") == 0) {
					incompleteFields.push("County");
				}
				if (incompleteFields.length > 0) {
					ret = andList(incompleteFields) + " are required";
				}
			break;
			case 5:
			
			break;		
		}
		return ret;
	},
	step: function() {
		switch (this.get("currentStep")) {
			case 1:
				this.set("user_id", 0);
				this.set("organization_id", 0);
				this.set("prevEmail", "");
			break;
			case 2:
				/*if (this.get("email") != this.get("prevEmail")) {
					var dupeEmails = getDuplicateEmails(this.get("email"));
					if (dupeEmails.length == 0) {
						this.set("user_id", 0);
					} else if (dupeEmails.length == 1) {
						this.set("user_id", parseInt(dupeEmails[0].user_id), 10);
					}
					this.set("prevEmail", this.get("email"));
				}*/
			break;
			case 3:
			
			break;
			case 4:
			
			break;
			case 5:
			
			break;	
		}
		return;
	},
	change: function() {
		this.set("dirty", true);
		//console.log(this);
		return;
	}
});
forgotPasswordViewModel = kendo.observable({
	dirty: false,
	email: "",
	passwordSent: false,
	sendPassword: function() {
		if (this.get("email").length > 7) {
			$.ajax({
				
			});
		}
	}
});